<!--#include file="../nav/account_top.php" -->
<style type="text/css">

/* 特殊处理 */
.main_content_title{
margin-left:0px;
margin-right:0px;
}
/* 移除全部 */
a.removealla{
background:url(/misc/images/account/shanchu.gif) center left no-repeat;
padding-left:15px;
color:gray;
}
/* 购物车商品 */
.combo_name{
font-size: 14px;
font-weight: bold;
margin: 10px auto;
color: #555555;
}

.vegeitem{
border: 1px dashed #CCCCCC;
color: #006600;
float: left;
margin-bottom: 10px;
margin-right: 10px;
padding: 5px 10px;
}

/* 购物车表格 */
table.carttb{
border-collapse:collapse;
width:100%;
}
table.carttb th{
color:#666666;
border-bottom: 1px solid #CECECE;
text-align:center;
padding:10px;
background-color:#E8EEF1;
}
table.carttb td{
color:#666666;
border-bottom: 1px dotted #CECECE;
text-align:center;
vertical-align:middle;
padding:5px;
}
table.carttb td.l{
text-align:left;
}
table.carttb td.r{
text-align:right;
}

input.numtext{
width:50px;
text-align:center;
}
/* 选菜份数增加减少按钮 */
.numclick{
background-color:#C3CDDC;
color:#606E7B;
border:1px solid #929CA7;
cursor:pointer;
} 
</style>
<div class="main_content_main">
	
	<div class="vpage_step">
		<ul class="step_ul">
			<li class="s_1 on">
				<div class="node">
					<span class="bg"></span>
					<p class="text">
						<i>1</i>
						购物车
					</p>
				</div>		
			</li>
			<li class="s_2">
				<div class="node">
					<span class="bg"></span>
					<p class="text">
						<i>2</i>
						结算订单
					</p>
				</div>		
			</li>
			<li class="s_3">
				<div class="node">
					<span class="bg"></span>
					<p class="text">
						<i>3</i>
						购买成功
					</p>
				</div>		
			</li>
		</ul>
	</div>
	
<!--  <div class="main_content_title">
		<span>购物车</span>
	</div> -->
	
	<!--购物车表格-->
	<div class="margin20">
		<table class="carttb">
			<thead>
				<Tr>
					<Th style="width:350px;">商品</Th>
					<Th>单价</Th>
					<Th>数量（套）</Th>
					<Th>小计</Th>
					<Th>操作</Th>
				</Tr>
			</thead>
			<tbody>
			<?PHP
			$num_total = 0;
			$price_total = 0;
			foreach($rs_cart as $v){//debug::show($v);
				$num_total += $v['nums'];
				$price_total += $v['price_total'];
				echo '
				<tr class="cart_tr" id="cart_tr_'.$v['id'].'" price="'.$v['price'].'" myid="'.$v['id'].'" >
					<td class="l" >
						<div class="combo_name">'.$v['combo_name'].'</div>
						<div class="combo_veges">';
				if($v['combo_type'] == '1'){
					foreach($v['cart_item'] as $val){
						echo '
							<div class="vegeitem">
								'.$val['vege_name'].'
								<span> '.$val['vege_num'].' 份</span>
							</div>';
					}
				}else{
					foreach($v['combo_item'] as $val){
						echo '
							<div class="vegeitem">
								'.$val['vege_name'].'
								<span> '.$val['vege_num'].' 份</span>
							</div>';
					}
				}
				echo '
							<div class="clear"></div>
						</div>
						<div class="combo_bdate">可配送时间：'.$v['sendbdate'].' 至 '.$v['sendedate'].'</div>
					</td>
					<td  >
						￥'.$v['price'].'
					</td>
					<td>
						<button class="numclick" onclick="fnShao('.$v['id'].')" title="点击减少商品数量">-</button>
						<input type="text"  value="'.$v['nums'].'" id="nums_'.$v['id'].'" readonly="readonly" class="numtext">
						<button class="numclick" onclick="fnAdd('.$v['id'].')"  title="点击增加商品数量">+</button> 
					</td>
					<td style="font-weight:bold" >
						￥<span id="price_total_'.$v['id'].'">'.func::fnDec($v['price_total'],2).'
					</td>
					<td>
						<a href="#" class="dela" onclick="fnDel('.$v['id'].')">删除</a>
					</td>
				</tr>';
			}
			?>
			</tbody>
		</table>
	</div>
	<div class="margin10" style="">
		<table style="border-collapse:collapse;width:100%">
			<Tr>
				<td style="text-align:left">
					<a style="display:none" href="#" onclick="fnDelAll()" class="removealla"  >清空购物车</a>
				</td>
				<td style="text-align:right">
					<div style="float:right">商品总计（不含运费）：<span style="font-weight:bold;font-size:16px;color:#FF3333">￥</span><span id="price_all" style="font-weight:bold;font-size:16px;color:#FF3333">{func::fnDec($price_total,2)}</span>
					</div> 
				</td>
			</Tr>
		</table>
	</div>
	<div style="margin:20px auto;text-align:right;"> 
		<?PHP
		if(count($rs_cart) >0 ){
			if($combosendarea === false){
				echo '<button class="btn_gray" onclick="fnGoConfirmDealNo()" >去结算</button>';
			}else{
				echo '<button class="btn_red" onclick="fnGoConfirmDeal()" >去结算</button>';
			}
		}	
		?>
	</div>
	
	
	<?PHP
if(count($rs_cart) >0 ){
	if($combosendarea === false){
	?>
	<style type="text/css">
	.alertdiv{
	background-color:#FFFFE3;
	border:1px solid #EBDBC5;
	color:#FF3333;
	padding:20px 40px;
	margin:5px auto;
	}
	</style>	
	<div class="alertdiv" id="nomoneydiv">
		您当前选择的菜品，可配送时间段不一致，请先选择部分菜品下单！
	</div>
	<?PHP
	}
}	
	?>
	<div  style="height:1px;line-height:1px"></div>
</div>
<script type="text/javascript">
var rs_cart = {json_encode($rs_cart)};
var url_delall = '/account_cart/deleteall';  
var url_delone = '/account_cart/deleteone';
var url_updatenum = '/account_cart/updatenum';
$().ready(function(){
	if(rs_cart.length == 0){
		ymPrompt.alert({message:'购物车没有任何商品，请先进行选菜',handler:function(){
			jumpTo('/account_buy/index');
		}}); 
	}
});
function fnGoConfirmDeal(){
	jumpTo('/account_cart/confirmdeal');
}
function fnGoConfirmDealNo(){
		ymPrompt.alert({
			message:'您当前选择的菜品，可配送时间段不一致，请先选择部分菜品下单！'
		}); 
}
/* 删除所有购物车 */
function fnDelAll(){
	fnConfirm({
		str:"确认清空购物车？",
		func_true:function(e){
			fnLoading('正在清空购物车');
			$('button').attr('disabled','disabled');
			$.post(
				url_delall,
				{
					
				},
				function(e){
					fnLoadingEnd();
					$('button').attr('disabled','');
					var ok = errorHandler(e);
					if(ok && ok.success=="1"){　 
						jumpTo('/account_cart/index');
					}
				}
			);
		}
	});
}
/* 删除单个 */
function fnDel(id){
	fnConfirm({
		str:"确认删除？",
		func_true:function(e){
			fnLoading('正在删除');
			$('button').attr('disabled','disabled');
			$.post(
				url_delone,
				{
					id:id
				},
				function(e){
					fnLoadingEnd();
					$('button').attr('disabled','');
					var ok = errorHandler(e);
					if(ok && ok.success=="1"){　 
						jumpTo('/account_cart/index');
					}
				}
			);
		}
	});
}

/* 重新计算价格 */
function fnCaclPrice(){
	var price_all=0;
	$('.cart_tr').each(function(){
		var id=$(this).attr('myid');
		var price=$(this).attr('price');
		var num=parseInt($('#nums_'+id).val(),10);
		var price_total = num*price;
		$('#price_total_'+id).html(fnDec(price_total,2));
		price_all += price_total;
	});
	$('#price_all').html(fnDec(price_all,2));
}



function fnShao(id){
	var vege_num =  parseInt(strToNum($('#nums_'+id).val()),10);
	var new_vege_num = vege_num - 1;
	if(new_vege_num <= 0){
		new_vege_num = 1;
	}
	$('#nums_'+id).val(new_vege_num);
	if(new_vege_num < vege_num){
		//做点事
		fnLoading('正在操作');
		$('button').attr('disabled','disabled');
		$.post(
			url_updatenum,
			{
				id:id,
				nums:new_vege_num
			},
			function(e){
				fnLoadingEnd();
				$('button').attr('disabled','');
				var ok = errorHandler(e);
				if(ok && ok.success=="1"){　
					fnCaclPrice(); 
					//jumpTo('/account_cart/index');
				}else{
					$('#nums_'+id).val(new_vege_num+1);
				}
			}
		); 
	}
}
function fnAdd(id){
	var vege_num =  parseInt(strToNum($('#nums_'+id).val()),10);
	var new_vege_num = vege_num + 1;
	if(new_vege_num <= 0){
		new_vege_num = 1;
	}
	$('#nums_'+id).val(new_vege_num);
	if(new_vege_num > vege_num){
		//做点事
		fnLoading('正在操作');
		$('button').attr('disabled','disabled');
		$.post(
			url_updatenum,
			{
				id:id,
				nums:new_vege_num
			},
			function(e){
				fnLoadingEnd();
				$('button').attr('disabled','');
				var ok = errorHandler(e);
				if(ok && ok.success=="1"){　 
					fnCaclPrice(); 
					//jumpTo('/account_cart/index');
				}else{
					$('#nums_'+id).val(new_vege_num-1);
				}
			}
		);
	}
}


</script>
<!--#include file="../nav/account_bottom.php" -->